#! /usr/bin/env python
#coding:utf8

import os
import shutil
import subprocess
import time

protoc = 'mProtos'
generated_out = 'generated'
python_out='%s\python'%(generated_out)
csharp_out='%s\csharp'%(generated_out)

# ABSPYTHON_OUT = os.path.join(os.path.abspath('.'),'')

# PROTOC = 'mProtos'

# os.rmdir 不能删除非空文件夹



# 这个相对路径也可以 绝对路径也可以
if(os.path.exists(generated_out)):  shutil.rmtree(generated_out)

time.sleep(0.3) # avoid windows explorer open conflicts

# 重新生成 PYTHON_OUT 目录
#os.makedirs(python_out)
#PROTOC_CMD='protoc-2.6.1-win32\protoc -I=%s --python_out=%s %s\*.proto'%(protoc,python_out,protoc)
#print(PROTOC_CMD)
#subprocess.call(PROTOC_CMD,shell=True)

os.makedirs(csharp_out)

PROTOC_CMD2 = 'protobuf-net\ProtoGen\protogen -i:%s\EctypeProto.proto -o:%s\EctypeProto.cs'%(protoc,csharp_out)
print(PROTOC_CMD2)
subprocess.call(PROTOC_CMD2,shell=True)

PROTOC_CMD2 = 'protobuf-net\ProtoGen\protogen -i:%s\RoleProto.proto -o:%s\RoleProto.cs'%(protoc,csharp_out)
print(PROTOC_CMD2)
subprocess.call(PROTOC_CMD2,shell=True)


#while True:
#    pass

# print(subPa
# for x in os.listdir(ABSPROTOC)



    # protoc-2.6.1-win32\protoc -I=protos --python_out=generated\python protos\dto\*.p
    # roto protos\enums\*.proto protos\msg_item\*.proto protos\msg_player\*.proto

# def test(suffix,tarDir=os.path.abspath('.')):
#     for curPath in os.listdir(tarDir):
#         curAbsPath = os.path.abspath(os.path.join(tarDir,curPath))
#         # print("curPath",curPath,"curAbsPath",curAbsPath)
#         if(os.path.isdir(curAbsPath)):
#         # if(os.path.isdir(curPath)) 也可以
#         # print(curPath,'is dir',curAbsPath)
#             test(suffix,curAbsPath)
#         elif(os.path.isfile(curAbsPath) and os.path.splitext(curAbsPath)[1] == suffix):
#             pass
        # elif(os.path.isfile(curPath)) 不可以 貌似判断isfile必须是绝对路径
        # print(curPath,"is file",curAbsPath)

